package com.infotop.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.infotop.entity.Circle;
import com.infotop.service.CircleService;
import com.infotop.utils.Result;
import com.infotop.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Dengjb
 * @since 2019-03-12
 */
@RestController
@CrossOrigin
@RequestMapping("/circle")
@Api(tags="兴趣圈API")
public class CircleController {

	@Autowired
	private CircleService circleService;

	@ApiOperation(value="获取用户创建的圈子", notes="根据传递参数获取")
	@PostMapping(path = "/getMyCreateCircle")
//	@RequiresRoles("admin")
//	@RequiresAuthentication
	public Result getMyCreateCircle(Circle circle, @RequestParam(value = "current", defaultValue = "1") int current,
	                                @RequestParam(value = "size", defaultValue = "10") int size) {
		QueryWrapper wrapper = new QueryWrapper();
		Page<Circle> selectPage = new Page<>();
		selectPage.setCurrent(current);
		selectPage.setSize(size);
		if(circle.getStatus()!=null){
			wrapper.eq("status",circle.getStatus());
		}
//		return ResultUtil.error(ResultENum.FAILD_CODE);
		return ResultUtil.success(circleService.page(selectPage,wrapper));
	}
}
